﻿$(function () {
    var url = new Url();
    var $Id = url.GetQueryString("id");
    var $css = url.GetQueryString("css");
    if ($Id) {//编辑模式，获取并绑定短信模板
        $.getJSON("../Handler/SMSTmpl.ashx",
            { Id: $Id, type: 4, _: Math.random() },
            function (result) {
                if (result.Status) {
                    $(".txtName").val(result.Data.TemplateName);
                    $(".txtTmplContent").val(result.Data.TemplateContent);
                } else {
                    alert(result.Message);
                }
            }
        );
    }
    //保存
    $(".btnSave").bind("click", function () {
        var $Name = $(".txtName").val();
        var $Content = $(".txtTmplContent").val();
        if ($Name == null || $Name == "") {
            $(".txtName").focus();
            $(".errorName").text("短信标题不能为空");
            return;
        }
        var type = $Id ? 2 : 1;
        $.getJSON("../Handler/SMSTmpl.ashx",
            { Name: $Name, Content: $Content, type: type,Id:$Id, _: Math.random() },
            function (result) {
                if (result.Status) {
                    location.href = "SMSTemplateList.aspx?css=" + $css;
                }
                else {
                    alert(result.Message);
                }
            }
        );
    });

    $(".txtName").change(function () {
        $(".errorName").text("");
    });

});